<?php
namespace app\api\controller\v5;


use app\api\controller\v2\Auth;
use app\astro\controller\Data;
use app\common\model\Recode;

class Astro extends Auth
{
    public $recode = [];
    public $AstroSet;
    public $Data;
    public $recodeModel;

    public function _initialize()
    {
        parent::_initialize();
        $this->AstroSet = new Astroset();
        $this->Data = new Data();
        $this->recodeModel = new Recode();
    }

    /**
     * 组合盘数据
     */
    public function composite($tt=[])
    {
        $id1 = input('id1/d', 0);
        $id2 = input('id2/d', 0);

        if (isset($tt) && $tt)
        {
            $id1 = $tt['id1'];
            $id2 = $tt['id2'];
            $tid = $tt['tid'];
        }
        $Data = $this->Data;
        $Set = $this->AstroSet;
        $astro_set = $Set->get(true, 'composite',false,$tid);// 内部调用
        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

        $map = ['id' =>$id1, 'uid' => $this->user['id']];

        $RecodeModel = $this->recodeModel;

        $userinfo1 = $RecodeModel->getRecode($map);

        $timestamp1 = $Data->deal_time($userinfo1);
        $utdatenow1 = strftime("%d.%m.%Y", $timestamp1);
        $utnow1 = strftime("%H:%M:%S", $timestamp1);
        $longitude1 = ($userinfo1['long_deg'] + $userinfo1['long_min'] / 60) * $userinfo1['ew'];
        $latitude1 = ($userinfo1['lat_deg'] + $userinfo1['lat_min'] / 60) * $userinfo1['ns'];

        $map['id'] = $id2;

        $userinfo2 = $RecodeModel->getRecode($map);
        $timestamp2 = $Data->deal_time($userinfo2);
        $utdatenow2 = strftime("%d.%m.%Y", $timestamp2);
        $utnow2 = strftime("%H:%M:%S", $timestamp2);
        $longitude2 = ($userinfo2['long_deg'] + $userinfo2['long_min'] / 60) * $userinfo2['ew'];
        $latitude2 = ($userinfo2['lat_deg'] + $userinfo2['lat_min'] / 60) * $userinfo2['ns'];

        $options1 = ['utdatenow' => $utdatenow1, 'utnow' => $utnow1, 'longitude' => $longitude1, 'latitude' => $latitude1, 'h_sys' => $astro_set['value']['h_sys']];

        $out1 = $Data->execData($options1);

        $options2 = ['utdatenow' => $utdatenow2, 'utnow' => $utnow2, 'longitude' => $longitude2, 'latitude' => $latitude2, 'h_sys' => $astro_set['value']['h_sys']];

        $out2 = $Data->execData($options2);

        $original_data1 = $Data->getOriginalData($out1, $astro_set['value']['h_sys']);
        $original_data2 = $Data->getOriginalData($out2, $astro_set['value']['h_sys']);

        $original_data = $Data->getTheCompoisteCenter($original_data1, $original_data2);

        $Data->array_remove($original_data, $Data->planets_display);
        $details = $Data->getPlanetHouseDetail($original_data, $original_data['hc1']);
        $phase = $Data->planetPkPlanet($original_data, $original_data, true);
        foreach ($phase['planets'] as $k => $d) {
            $details['planets'][$k]['phase'] = $d['phase'];
            if (empty($d['phase'])) $details['planets'][$k]['phase'] = null;
        }
        $details['phase'] = $phase['phase'];

        $details['planets'] = (object)$details['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        if (isset($tt) && $tt)
        {
            return $details;
        }else{
            return show(config('code.success'),'Success.',$details);
        }
    }

    /**
     * 组次盘数据
     */
    public function composite_progressions($tt=[])
    {
        $timeinfo =[];
        $id1 = input('id1/d', 0);
        $id2 = input('id2/d', 0);
        $datetime = htmlspecialchars(input('datetime'));
        $timeinfo['timezone'] = (int)(input('timezone'));


        if (isset($tt) && $tt)
        {
            $id1 = $tt['id1'];
            $id2 = $tt['id2'];
            $datetime = $tt['datetime'];
            $timeinfo['timezone'] = $tt['timezone'];
            $tid = $tt['tid'];
        }

        $time = strtotime($datetime);
        $timeinfo['year'] = date('Y',$time);
        $timeinfo['month'] = date('m',$time);
        $timeinfo['day'] = date('d',$time);
        $timeinfo['hour'] = date('H',$time);
        $timeinfo['minute'] = date('i',$time);

        $Data = $this->Data;
        $Set = $this->AstroSet;
        $astro_set = $Set->get(true, 'composite_progressions');// 内部调用
        $h_sys = $astro_set['value']['h_sys'];
        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

        $map = ['id' => $id1, 'uid' => $this->user['id']];

        $RecodeModel = $this->recodeModel;

        $userinfo1 = $RecodeModel->getRecode($map);

        $timestamp1 = $Data->deal_time($userinfo1);
        $longitude1 = ($userinfo1['long_deg'] + $userinfo1['long_min'] / 60) * $userinfo1['ew'];
        $latitude1 = ($userinfo1['lat_deg'] + $userinfo1['lat_min'] / 60) * $userinfo1['ns'];

        $map['id'] = $id2;

        $userinfo2 = $RecodeModel->getRecode($map);
        $timestamp2 = $Data->deal_time($userinfo2);
        $longitude2 = ($userinfo2['long_deg'] + $userinfo2['long_min'] / 60) * $userinfo2['ew'];
        $latitude2 = ($userinfo2['lat_deg'] + $userinfo2['lat_min'] / 60) * $userinfo2['ns'];


        $timeinfo['is_summer'] = isSummerTime($timeinfo['hour'], $timeinfo['minute'], 0,
            $timeinfo['month'], $timeinfo['day'], $timeinfo['year']) ? 1 : 0;

        $timestamp3 = $Data->deal_time($timeinfo);

        $birth_JD1 = gregoriantojd(date('m', $timestamp1), date('d', $timestamp1), date('Y', $timestamp1)) + ((date('H', $timestamp1) + (date('i', $timestamp1) / 60)) / 24);
        $birth_JD2 = gregoriantojd(date('m', $timestamp2), date('d', $timestamp2), date('Y', $timestamp2)) + ((date('H', $timestamp2) + (date('i', $timestamp2) / 60)) / 24);
        $start_JD = gregoriantojd(date('m', $timestamp3), date('d', $timestamp3), date('Y', $timestamp3)) + ((date('H', $timestamp3) + (date('i', $timestamp3) / 60)) / 24);
        $days_alive1 = $start_JD - $birth_JD1; // 总天数
        $days_alive2 = $start_JD - $birth_JD2; // 总天数
        $prog_time_to_add1 = $days_alive1 / 365.2422;// 365.2422  365.2421990  365.25
        $prog_time_to_add2 = $days_alive2 / 365.2422;// 365.2422  365.2421990  365.25

        $time_before_JD1 = $birth_JD1 + floor($prog_time_to_add1);
        $time_before_JD2 = $birth_JD2 + floor($prog_time_to_add2);

        //变化比率 //就是$prog_time_to_add的去掉整数的小数
        $time_change_pro1 = $prog_time_to_add1 - floor($prog_time_to_add1);
        $time_change_pro2 = $prog_time_to_add2 - floor($prog_time_to_add2);

        $date_before1 = strtotime(jdtogregorian($time_before_JD1));
        $date_after1 = strtotime('+1 day', $date_before1);

        $date_before2 = strtotime(jdtogregorian($time_before_JD2));
        $date_after2 = strtotime('+1 day', $date_before2);

        $utdatenow1 = strftime("%d.%m.%Y", $date_before1);
        $utnow1 = strftime("%H:%M:%S", $timestamp1);

        $utdatenow2 = strftime("%d.%m.%Y", $date_after1);
        $utnow2 = strftime("%H:%M:%S", $timestamp1);

        $utdatenow3 = strftime("%d.%m.%Y", $date_after2);
        $utnow3 = strftime("%H:%M:%S", $timestamp2);

        $utdatenow4 = strftime("%d.%m.%Y", $date_after2);
        $utnow4 = strftime("%H:%M:%S", $timestamp2);

        $options1 = ['utdatenow' => $utdatenow1, 'utnow' => $utnow1, 'longitude' => $longitude1, 'latitude' => $latitude1, 'h_sys' => $h_sys];
        $options2 = ['utdatenow' => $utdatenow2, 'utnow' => $utnow2, 'longitude' => $longitude1, 'latitude' => $latitude1, 'h_sys' => $h_sys];
        $options3 = ['utdatenow' => $utdatenow3, 'utnow' => $utnow3, 'longitude' => $longitude2, 'latitude' => $latitude2, 'h_sys' => $h_sys];
        $options4 = ['utdatenow' => $utdatenow4, 'utnow' => $utnow4, 'longitude' => $longitude2, 'latitude' => $latitude2, 'h_sys' => $h_sys];

        $out1 = $Data->execData($options1);
        $out2 = $Data->execData($options2);
        $out3 = $Data->execData($options3);
        $out4 = $Data->execData($options4);

        $calOut1 = $Data->getProgressionThirdprogressed($out1, $out2, $time_change_pro1);
        $calOut2 = $Data->getProgressionThirdprogressed($out3, $out4, $time_change_pro2);


        $original_data1 = $Data->getOriginalData($calOut1, $h_sys);
        $original_data2 = $Data->getOriginalData($calOut2, $h_sys);

        $original_data = $Data->getTheCompoisteCenter($original_data1, $original_data2);

        $Data->array_remove($original_data, $Data->planets_display);
        $details = $Data->getPlanetHouseDetail($original_data, $original_data['hc1']);
        $phase = $Data->planetPkPlanet($original_data, $original_data, true);
        foreach ($phase['planets'] as $k => $d) {
            $details['planets'][$k]['phase'] = $d['phase'];
            if (empty($d['phase'])) $details['planets'][$k]['phase'] = null;
        }
        $details['phase'] = $phase['phase'];

        $details['planets'] = (object)$details['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        if (isset($tt) && $tt)
        {
            return $details;
        }else{
            return show(config('code.success'),'Success.',$details);
        }
    }

    /**
     * 组三盘数据
     */
    public function composite_thirdprogressed($tt=[])
    {
        $timeinfo =[];
        $id1 = input('id1/d', 0);
        $id2 = input('id2/d', 0);
        $datetime = htmlspecialchars(input('datetime'));
        $timeinfo['timezone'] = (int)(input('timezone'));


        if (isset($tt) && $tt)
        {
            $id1 = $tt['id1'];
            $id2 = $tt['id2'];
            $datetime = $tt['datetime'];
            $timeinfo['timezone'] = $tt['timezone'];
            $tid = $tt['tid'];
        }

        $time = strtotime($datetime);
        $timeinfo['year'] = date('Y',$time);
        $timeinfo['month'] = date('m',$time);
        $timeinfo['day'] = date('d',$time);
        $timeinfo['hour'] = date('H',$time);
        $timeinfo['minute'] = date('i',$time);

        $Data = $this->Data;
        $Set = $this->AstroSet;
        $astro_set = $Set->get(true,'composite_thirdprogressed',false,$tid);// 内部调用
        $h_sys = $astro_set['value']['h_sys'];
        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

        $map = ['id' =>$id1, 'uid' => $this->user['id']];

        $RecodeModel = $this->recodeModel;

        $userinfo1 = $RecodeModel->getRecode($map);

        $timestamp1 = $Data->deal_time($userinfo1);
        $longitude1 = ($userinfo1['long_deg'] + $userinfo1['long_min'] / 60) * $userinfo1['ew'];
        $latitude1 = ($userinfo1['lat_deg'] + $userinfo1['lat_min'] / 60) * $userinfo1['ns'];

        $map['id'] = $id2;

        $userinfo2 = $RecodeModel->getRecode($map);
        $timestamp2 = $Data->deal_time($userinfo2);
        $longitude2 = ($userinfo2['long_deg'] + $userinfo2['long_min'] / 60 ) * $userinfo2['ew'];
        $latitude2 = ($userinfo2['lat_deg'] + $userinfo2['lat_min'] / 60 ) * $userinfo2['ns'];

        $timeinfo['is_summer'] = isSummerTime($timeinfo['hour'],$timeinfo['minute'],0,
            $timeinfo['month'],$timeinfo['day'],$timeinfo['year']) ? 1 : 0;

        $timestamp3 = $Data->deal_time($timeinfo);

        $birth_JD1 = gregoriantojd(date('m',$timestamp1), date('d',$timestamp1), date('Y',$timestamp1)) + ((date('H',$timestamp1) + (date('i',$timestamp1) / 60)) / 24);
        $birth_JD2 = gregoriantojd(date('m',$timestamp2), date('d',$timestamp2), date('Y',$timestamp2)) + ((date('H',$timestamp2) + (date('i',$timestamp2) / 60)) / 24);
        $start_JD = gregoriantojd(date('m',$timestamp3), date('d',$timestamp3), date('Y',$timestamp3)) + ((date('H',$timestamp3) + (date('i',$timestamp3) / 60)) / 24);
        $days_alive1 = $start_JD - $birth_JD1; // 总天数
        $days_alive2 = $start_JD - $birth_JD2; // 总天数
        $prog_time_to_add1 = $days_alive1 / 27.32166; // 多少月27.321661     27.3215865
        $prog_time_to_add2 = $days_alive2 / 27.32166; // 多少月27.321661     27.3215865

        $time_before_JD1=$birth_JD1+floor($prog_time_to_add1);
        $time_before_JD2=$birth_JD2+floor($prog_time_to_add2);

        //变化比率 //就是$prog_time_to_add的去掉整数的小数
        $time_change_pro1=$prog_time_to_add1-floor($prog_time_to_add1);
        $time_change_pro2=$prog_time_to_add2-floor($prog_time_to_add2);

        $date_before1 = strtotime(jdtogregorian($time_before_JD1));
        $date_after1 = strtotime('+1 day',$date_before1);

        $date_before2 = strtotime(jdtogregorian($time_before_JD2));
        $date_after2 = strtotime('+1 day',$date_before2);

        $utdatenow1 = strftime("%d.%m.%Y", $date_before1);
        $utnow1 = strftime("%H:%M:%S", $timestamp1);

        $utdatenow2 = strftime("%d.%m.%Y", $date_after1);
        $utnow2 = strftime("%H:%M:%S", $timestamp1);

        $utdatenow3 = strftime("%d.%m.%Y", $date_after2);
        $utnow3 = strftime("%H:%M:%S", $timestamp2);

        $utdatenow4 = strftime("%d.%m.%Y", $date_after2);
        $utnow4 = strftime("%H:%M:%S", $timestamp2);

        $options1 = ['utdatenow' => $utdatenow1, 'utnow' => $utnow1, 'longitude' => $longitude1, 'latitude' => $latitude1, 'h_sys' => $h_sys];
        $options2 = ['utdatenow' => $utdatenow2, 'utnow' => $utnow2, 'longitude' => $longitude1, 'latitude' => $latitude1, 'h_sys' => $h_sys];
        $options3 = ['utdatenow' => $utdatenow3, 'utnow' => $utnow3, 'longitude' => $longitude2, 'latitude' => $latitude2, 'h_sys' => $h_sys];
        $options4 = ['utdatenow' => $utdatenow4, 'utnow' => $utnow4, 'longitude' => $longitude2, 'latitude' => $latitude2, 'h_sys' => $h_sys];

        $out1 = $Data->execData($options1);
        $out2 = $Data->execData($options2);
        $out3 = $Data->execData($options3);
        $out4 = $Data->execData($options4);

        $calOut1 = $Data->getProgressionThirdprogressed($out1,$out2,$time_change_pro1);
        $calOut2 = $Data->getProgressionThirdprogressed($out3,$out4,$time_change_pro2);


        $original_data1 = $Data->getOriginalData($calOut1,$h_sys);
        $original_data2 = $Data->getOriginalData($calOut2,$h_sys);

        $original_data = $Data->getTheCompoisteCenter($original_data1,$original_data2);

        $Data->array_remove($original_data,$Data->planets_display);
        $details = $Data->getPlanetHouseDetail($original_data, $original_data['hc1']);
        $phase = $Data->planetPkPlanet($original_data, $original_data, true);
        foreach ($phase['planets'] as $k => $d)
        {
            $details['planets'][$k]['phase'] = $d['phase'];
            if(empty($d['phase'])) $details['planets'][$k]['phase'] = null;
        }
        $details['phase'] = $phase['phase'];

        $details['planets'] = (object)$details['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        if (isset($tt) && $tt)
        {
            return $details;
        }else{
            return show(config('code.success'),'Success.',$details);
        }
    }

    /**
     *时空盘数据
     */
    public function davison($tt=[])
    {
        $id1 = input('id1/d', 0);
        $id2 = input('id2/d', 0);

        if (isset($tt) && $tt)
        {
            $id1 = $tt['id1'];
            $id2 = $tt['id2'];
            $tid = $tt['tid'];
        }

        $Data = $this->Data;
        $Set = $this->AstroSet;
        $astro_set = $Set->get(true,'davison',false,$tid);// 内部调用
        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

        $map = ['id' => $id1, 'uid' => $this->user['id']];

        $RecodeModel = $this->recodeModel;

        $userinfo1 = $RecodeModel->getRecode($map);

        $map['id'] = $id2;
        $userinfo2 = $RecodeModel->getRecode($map);

        $timestamp1 = $Data->deal_time($userinfo1);
        $timestamp2 = $Data->deal_time($userinfo2);

        $longitude1 = ($userinfo1['long_deg'] + $userinfo1['long_min'] / 60 ) * $userinfo1['ew'];
        $latitude1 = ($userinfo1['lat_deg'] + $userinfo1['lat_min'] / 60 ) * $userinfo1['ns'];
        $longitude2 = ($userinfo2['long_deg'] + $userinfo2['long_min'] / 60 ) * $userinfo2['ew'];
        $latitude2 = ($userinfo2['lat_deg'] + $userinfo2['lat_min'] / 60 ) * $userinfo2['ns'];

        $timestamp = ($timestamp1 + $timestamp2) /2 ;
        $utdatenow = strftime("%d.%m.%Y", $timestamp);
        $utnow = strftime("%H:%M:%S", $timestamp);
        $longitude = ($longitude1 + $longitude2) / 2;
        $latitude = ($latitude1 + $latitude2) / 2;

        $options = [
            'utdatenow' => $utdatenow,
            'utnow' => $utnow,
            'longitude' => $longitude,
            'latitude' => $latitude,
            'h_sys' => $astro_set['value']['h_sys'],
        ];

        $out = $Data->execData($options);

        $original_data = $Data->getOriginalData($out,$astro_set['value']['h_sys']);
        $Data->array_remove($original_data,$Data->planets_display);
        $details = $Data->getPlanetHouseDetail($original_data, $original_data['hc1']);
        $phase = $Data->planetPkPlanet($original_data, $original_data,true);
        foreach ($phase['planets'] as $k => $d)
        {
            $details['planets'][$k]['phase'] = $d['phase'];
            if(empty($d['phase'])) $details['planets'][$k]['phase'] = null;
        }
        $details['phase'] = $phase['phase'];

        $details['planets'] = (object)$details['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        if (isset($tt) && $tt)
        {
            return $details;
        }else{
            return show(config('code.success'),'Success.',$details);
        }
    }

    /**
     * 月返盘数据
     */
    public function lunar_return($tt=[])
    {
        $timeinfo=[];
        $datetime = htmlspecialchars(input('datetime'));
        $timeinfo['timezone'] = (int)(input('timezone'));
        $id = input('id/d', 0);

        if (isset($tt) && $tt)
        {
            $datetime = $tt['datetime'];
            $timeinfo['timezone'] = $tt['timezone'];
            $id = $tt['id'];
            $tid = $tt['tid'];
        }


        $time = strtotime($datetime);
        $timeinfo['year'] = date('Y',$time);
        $timeinfo['month'] = date('m',$time);
        $timeinfo['day'] = date('d',$time);
        $timeinfo['hour'] = date('H',$time);
        $timeinfo['minute'] = date('i',$time);

        $timeinfo['is_summer'] = isSummerTime($timeinfo['hour'], $timeinfo['minute'], 0,
            $timeinfo['month'], $timeinfo['day'], $timeinfo['year']) ? 1 : 0;

        $Data = $this->Data;

        $map = ['id' => $id, 'uid' => $this->user['id']];

        $RecodeModel = $this->recodeModel;

        $userinfo = $RecodeModel->getRecode($map);
        $timestamp1 = $Data->deal_time($userinfo);

        $longitude = ($userinfo['long_deg'] + $userinfo['long_min'] / 60) * $userinfo['ew'];
        $latitude = ($userinfo['lat_deg'] + $userinfo['lat_min'] / 60) * $userinfo['ns'];

        $timestamp2 = $Data->deal_time($timeinfo);

        $birth_JD = gregoriantojd(date('m', $timestamp1), date('d', $timestamp1), date('Y', $timestamp1)) + ((date('H', $timestamp1) + (date('i', $timestamp1) / 60)) / 24);
        $start_JD = gregoriantojd(date('m', $timestamp2), date('d', $timestamp2), date('Y', $timestamp2)) + ((date('H', $timestamp2) + (date('i', $timestamp2) / 60)) / 24);
        $days_alive = $start_JD - $birth_JD; // 总天数

        $month_ago = floor($days_alive / 27.321661);// 总月数
        $day_ago = floor($month_ago * 27.321661);
        $now_before = strtotime("+$day_ago day", $timestamp1);
        $now_after = strtotime("+1 day", $now_before);

        $utdatenow = strftime("%d.%m.%Y", $timestamp1);
        $utnow = strftime("%H:%M:%S", $timestamp1);

        $utdatenow1 = strftime("%d.%m.%Y", $now_before);
        $utnow1 = strftime("%H:%M:%S", $now_before);

        $utdatenow2 = strftime("%d.%m.%Y", $now_after);
        $utnow2 = strftime("%H:%M:%S", $now_after);

        $Set = $this->AstroSet;

        $astro_set = $Set->get(true, 'lunar_return',false,$tid);// 内部调用
        $h_sys = $astro_set['value']['h_sys'];

        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

        $options1 = ['utdatenow' => $utdatenow, 'utnow' => $utnow, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];
        $options2 = ['utdatenow' => $utdatenow1, 'utnow' => $utnow1, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];
        $options3 = ['utdatenow' => $utdatenow2, 'utnow' => $utnow2, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];

        $out1 = $Data->execData($options1);
        $out2 = $Data->execData($options2);
        $out3 = $Data->execData($options3);

        // 出生生日那一天月亮位置
        $longtitude1 = number_format(explode(',', $out1[1])[0] * 1, 3);
        // 当年生日前一天的月亮位置
        $longtitude2 = number_format(explode(',', $out2[1])[0] * 1, 3);
        // 当年生日后一天月亮位置
        $longtitude3 = number_format(explode(',', $out3[1])[0] * 1, 3);

        $diff_longtitude = round(abs($longtitude3 - $longtitude2), 6);//度数差

        $diff_minutes = 24 * 60 * 60;//精确到秒

        $diff_influence = $diff_longtitude / $diff_minutes;// 每秒钟走的度数

        // 需要多少时间  回到需要的度数
        $second = round(abs($longtitude1 - $longtitude2) / $diff_influence);// 总秒钟数

        if ($longtitude1 < $longtitude2) $now_before -= $second;

        else $now_before += $second;

        $now_before = $now_before - ($now_before % 60);// 只精确到分钟

        $utdatenow_test = strftime("%d.%m.%Y", $now_before);
        $utnow_test = strftime("%H:%M:%S", $now_before);

        $options = ['utdatenow' => $utdatenow_test, 'utnow' => $utnow_test, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];

        $out = $Data->execData($options);

        $original_data = $Data->getOriginalData($out, $h_sys);
        $Data->array_remove($original_data, $Data->planets_display);

        $details = $Data->getPlanetHouseDetail($original_data, $original_data['hc1']);
        $phase = $Data->planetPkPlanet($original_data, $original_data, true);
        foreach ($phase['planets'] as $k => $d) {
            $details['planets'][$k]['phase'] = $d['phase'];
            if (empty($d['phase'])) $details['planets'][$k]['phase'] = null;
        }
        $details['phase'] = $phase['phase'];

        $details['planets'] = (object)$details['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        $details['return_time'] = date("Y-m-d H:i", $now_before + $userinfo['timezone'] * 3600);

        if (isset($tt) && $tt)
        {
            return $details;
        }else{
            return show(config('code.success'),'Success.',$details);
        }
    }

    /**
     * 马盘数据
     */
    public function marks($tt=[])
    {
        $id1 = input('id1/d', 0);
        $id2 = input('id2/d', 0);

        if (isset($tt) && $tt)
        {
            $id1 = $tt['id1'];
            $id2 = $tt['id2'];
            $tid = $tt['tid'];
        }

        $Data = $this->Data;
        $Set = $this->AstroSet;
        $astro_set = $Set->get(true,'marks',false,$tid);// 内部调用
        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

        $map = ['id' => $id1, 'uid' => $this->user['id']];

        $RecodeModel = $this->recodeModel;

        $userinfo1 = $RecodeModel->getRecode($map);

        $map['id'] = $id2;
        $userinfo2 = $RecodeModel->getRecode($map);

        $timestamp1 = $Data->deal_time($userinfo1);
        $timestamp2 = $Data->deal_time($userinfo2);

        $longitude1 = ($userinfo1['long_deg'] + $userinfo1['long_min'] / 60 ) * $userinfo1['ew'];
        $latitude1 = ($userinfo1['lat_deg'] + $userinfo1['lat_min'] / 60 ) * $userinfo1['ns'];
        $longitude2 = ($userinfo2['long_deg'] + $userinfo2['long_min'] / 60 ) * $userinfo2['ew'];
        $latitude2 = ($userinfo2['lat_deg'] + $userinfo2['lat_min'] / 60 ) * $userinfo2['ns'];

        $timestamp = 0.75 * $timestamp1 + 0.25 * $timestamp2;
        $utdatenow = strftime("%d.%m.%Y", $timestamp);
        $utnow = strftime("%H:%M:%S", $timestamp);
        $longitude = 0.75 * $longitude1 + 0.25 * $longitude2;
        $latitude = 0.75 * $latitude1 + 0.25 * $latitude2;

        $options = [
            'utdatenow' => $utdatenow,
            'utnow' => $utnow,
            'longitude' => $longitude,
            'latitude' => $latitude,
            'h_sys' => $astro_set['value']['h_sys'],
        ];

        $out = $Data->execData($options);

//        $exec_str = config('astrolog.prefix')." -b{$utdatenow} -ut{$utnow} -p0123456789DAmHt -eswe -house{$longitude},{$latitude},{$astro_set['value']['h_sys']} -flds -g, -head";
//
//        exec ($exec_str, $out);
        $original_data = $Data->getOriginalData($out,$astro_set['value']['h_sys']);
        $Data->array_remove($original_data,$Data->planets_display);
        $details = $Data->getPlanetHouseDetail($original_data, $original_data['hc1']);
        $phase = $Data->planetPkPlanet($original_data, $original_data,true);
        foreach ($phase['planets'] as $k => $d)
        {
            $details['planets'][$k]['phase'] = $d['phase'];
            if(empty($d['phase'])) $details['planets'][$k]['phase'] = null;
        }
        $details['phase'] = $phase['phase'];

        $details['planets'] = (object)$details['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        if (isset($tt) && $tt)
        {
            return $details;
        }else{
            return show(config('code.success'),'Success.',$details);
        }
    }

    /**
     * 次限单盘数据
     */
    public function progressions($tt=[])
    {
        $timeinfo=[];
        $datetime = htmlspecialchars(input('datetime'));
        $timeinfo['timezone'] = (int)(input('timezone'));
        $id = input('id/d',0);

        if (isset($tt) && $tt)
        {
            $datetime = $tt['datetime'];
            $timeinfo['timezone'] = $tt['timezone'];
            $id = $tt['id'];
            $tid = $tt['tid'];
        }

        $Set = $this->AstroSet;
        $astro_set = $Set->get(true,'progressions',false,$tid);// 内部调用
        $Data = $this->Data;
        $h_sys = $astro_set['value']['h_sys'];
        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];


        $time = strtotime($datetime);
        $timeinfo['year'] = date('Y',$time);
        $timeinfo['month'] = date('m',$time);
        $timeinfo['day'] = date('d',$time);
        $timeinfo['hour'] = date('H',$time);
        $timeinfo['minute'] = date('i',$time);

        $timeinfo['is_summer'] = isSummerTime($timeinfo['hour'],$timeinfo['minute'],0,
            $timeinfo['month'],$timeinfo['day'],$timeinfo['year']) ? 1 : 0;

        $map = ['id' => $id, 'uid' => $this->user['id']];

        $userinfo = $this->recodeModel->getRecode($map);

        $timestamp1 = $Data->deal_time($userinfo);

        $utdatenow = strftime("%d.%m.%Y", $timestamp1);
        $utnow = strftime("%H:%M:%S", $timestamp1);

        $longitude = ($userinfo['long_deg'] + $userinfo['long_min'] / 60 ) * $userinfo['ew'];
        $latitude = ($userinfo['lat_deg'] + $userinfo['lat_min'] / 60 ) * $userinfo['ns'];

        $exec_str  = config('astrolog.prefix')." -b{$utdatenow} -ut{$utnow} -p0 -eswe -house{$longitude},{$latitude},{$h_sys} -fj -g, -head";
        exec ($exec_str, $out);

        $timestamp2 = $Data->deal_time($timeinfo);

        $birth_JD = gregoriantojd(date('m',$timestamp1), date('d',$timestamp1), date('Y',$timestamp1)) + ((date('H',$timestamp1) + (date('i',$timestamp1) / 60)) / 24);
        $start_JD = gregoriantojd(date('m',$timestamp2), date('d',$timestamp2), date('Y',$timestamp2)) + ((date('H',$timestamp2) + (date('i',$timestamp2) / 60)) / 24);
        $days_alive = $start_JD - $birth_JD; // 总天数
        $prog_time_to_add = $days_alive / 365.2422;// 365.2422  365.2421990  365.25

        // 夜间盘
        if($out[0] > 0 || $out[0] < 7)
        {
            $time_before_JD=$birth_JD+floor($prog_time_to_add);
        }
        else
        {
            $time_before_JD=$birth_JD+floor($prog_time_to_add);
        }


        //变化比率 //就是$prog_time_to_add的去掉整数的小数
        $time_change_pro=$prog_time_to_add-floor($prog_time_to_add);

        $date_before = strtotime(jdtogregorian($time_before_JD));
        $date_after = strtotime('+1 day',$date_before);

        $utdatenow1 = strftime("%d.%m.%Y", $date_before);
        $utnow1 = strftime("%H:%M:%S", $timestamp1);


        $utdatenow2 = strftime("%d.%m.%Y", $date_after);
        $utnow2 = strftime("%H:%M:%S", $timestamp1);

        $options1 = ['utdatenow' => $utdatenow1, 'utnow' => $utnow1, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];
        $options2 = ['utdatenow' => $utdatenow2, 'utnow' => $utnow2, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];

        $out1 = $Data->execData($options1);
        $out2 = $Data->execData($options2);

        $calOut = $Data->getProgressionThirdprogressed($out1,$out2,$time_change_pro);

        $original_data = $Data->getOriginalData($calOut,$h_sys);
        $Data->array_remove($original_data,$Data->planets_display);

        $details = $Data->getPlanetHouseDetail($original_data, $original_data['hc1']);
        $phase = $Data->planetPkPlanet($original_data, $original_data, true);
        foreach ($phase['planets'] as $k => $d)
        {
            $details['planets'][$k]['phase'] = $d['phase'];
            if(empty($d['phase'])) $details['planets'][$k]['phase'] = null;
        }
        $details['phase'] = $phase['phase'];

        $details['time1'] = date('Y-m-d H:i:s',$date_before);

        $details['planets'] = (object)$details['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        if (isset($tt) && $tt)
        {
            return $details;
        }else{
            return show(config('code.success'),'Success.',$details);
        }
    }

    /**
     * 次限双盘数据
     */
    public function progressionsvsnatal($tt=[])
    {
        $timeinfo=[];
        $datetime = htmlspecialchars(input('datetime'));
        $timeinfo['timezone'] = (int)(input('timezone'));
        $id = input('id/d',0);

        if (isset($tt) && $tt)
        {
            $datetime = $tt['datetime'];
            $timeinfo['timezone'] = $tt['timezone'];
            $id = $tt['id'];
            $tid = $tt['tid'];
        }

        $Set = $this->AstroSet;
        $astro_set = $Set->get(true,'progressionsvsnatal',false,$tid);// 内部调用
        $Data = $this->Data;
        $h_sys = $astro_set['value']['h_sys'];
        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

        $time = strtotime($datetime);
        $timeinfo['year'] = date('Y',$time);
        $timeinfo['month'] = date('m',$time);
        $timeinfo['day'] = date('d',$time);
        $timeinfo['hour'] = date('H',$time);
        $timeinfo['minute'] = date('i',$time);

        $timeinfo['is_summer'] = isSummerTime($timeinfo['hour'],$timeinfo['minute'],0,
            $timeinfo['month'],$timeinfo['day'],$timeinfo['year']) ? 1 : 0;

        $map = ['id' => $id, 'uid' => $this->user['id']];

        $userinfo = $this->recodeModel->getRecode($map);

        $timestamp1 = $Data->deal_time($userinfo);

        $utdatenow = strftime("%d.%m.%Y", $timestamp1);
        $utnow = strftime("%H:%M:%S", $timestamp1);

        $longitude = ($userinfo['long_deg'] + $userinfo['long_min'] / 60 ) * $userinfo['ew'];
        $latitude = ($userinfo['lat_deg'] + $userinfo['lat_min'] / 60 ) * $userinfo['ns'];

        $exec_str  = config('astrolog.prefix')." -b{$utdatenow} -ut{$utnow} -p0 -eswe -house{$longitude},{$latitude},{$h_sys} -fj -g, -head";
        exec ($exec_str, $out);

        $timestamp2 = $Data->deal_time($timeinfo);

        $birth_JD = gregoriantojd(date('m',$timestamp1), date('d',$timestamp1), date('Y',$timestamp1)) + ((date('H',$timestamp1) + (date('i',$timestamp1) / 60)) / 24);
        $start_JD = gregoriantojd(date('m',$timestamp2), date('d',$timestamp2), date('Y',$timestamp2)) + ((date('H',$timestamp2) + (date('i',$timestamp2) / 60)) / 24);
        $days_alive = $start_JD - $birth_JD; // 总天数
        $prog_time_to_add = $days_alive / 365.2422;// 365.2422  365.2421990  365.25
//        echo $days_alive."<br/>";
        // 夜间盘
        if($out[0] > 0 || $out[0] < 7)
        {
            $time_before_JD=$birth_JD+floor($prog_time_to_add);
        }
        else
        {
            $time_before_JD=$birth_JD+floor($prog_time_to_add);
        }


        //变化比率 //就是$prog_time_to_add的去掉整数的小数
        $time_change_pro=$prog_time_to_add-floor($prog_time_to_add);

        $date_before = strtotime(jdtogregorian($time_before_JD));
        $date_after = strtotime('+1 day',$date_before);

        $utdatenow1 = strftime("%d.%m.%Y", $date_before);
        $utnow1 = strftime("%H:%M:%S", $timestamp1);

        $utdatenow2 = strftime("%d.%m.%Y", $date_after);
        $utnow2 = strftime("%H:%M:%S", $timestamp1);

        $options1 = ['utdatenow' => $utdatenow1, 'utnow' => $utnow1, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];
        $options2 = ['utdatenow' => $utdatenow2, 'utnow' => $utnow2, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];
        $options3 = ['utdatenow' => $utdatenow, 'utnow' => $utnow, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];

        $out1 = $Data->execData($options1);
        $out2 = $Data->execData($options2);
        $out_natal = $Data->execData($options3);


//        $exec_str1 = config('astrolog.prefix')." -b{$utdatenow1} -ut{$utnow1} -p0123456789DAmHt -eswe -house{$longitude},{$latitude},{$h_sys} -flds -g, -head";
//        $exec_str2 = config('astrolog.prefix')." -b{$utdatenow2} -ut{$utnow2} -p0123456789DAmHt -eswe -house{$longitude},{$latitude},{$h_sys} -flds -g, -head";
//        $exec_str_natal  = config('astrolog.prefix')." -b{$utdatenow} -ut{$utnow} -p0123456789DAmHt -eswe -house{$longitude},{$latitude},{$h_sys} -flds -g, -head";
//
//        exec ($exec_str1, $out1);
//        exec ($exec_str2, $out2);
//        exec ($exec_str_natal, $out_natal);
        $calOut = $Data->getProgressionThirdprogressed($out1,$out2,$time_change_pro);

        $original_data1 = $Data->getOriginalData($out_natal,$h_sys);
        $original_data2 = $Data->getOriginalData($calOut,$h_sys);
        $Data->array_remove($original_data1,$Data->planets_display);
        $Data->array_remove($original_data2,$Data->planets_display);
        $details1 = $Data->getPlanetHouseDetail($original_data1, $original_data1['hc1']);
        $details2 = $Data->getPlanetHouseDetail($original_data2, $original_data1['hc1']);
        $phase1 = $Data->planetPkPlanet($original_data1, $original_data2);
        $phase2 = $Data->planetPkPlanet($original_data2, $original_data1);
        foreach ($phase1['planets'] as $k1 => $d1)
        {
            $details1['planets'][$k1]['phase'] = $d1['phase'];
            if(empty($d1['phase'])) $details1['planets'][$k1]['phase'] = null;
        }
        foreach ($phase2['planets'] as $k2 => $d2)
        {
            $details2['planets'][$k2]['phase'] = $d2['phase'];
            if(empty($d2['phase'])) $details2['planets'][$k2]['phase'] = null;
        }
        $details1['phase'] = $phase1['phase'];
        $details2['phase'] = $phase2['phase'];


        $details1['planets'] = (object)$details1['planets'];// 指定输出为object  防止所有行星全开时 类型改变
        $details2['planets'] = (object)$details2['planets'];// 指定输出为object  防止所有行星全开时 类型改变

//        $details['time1'] = date('Y-m-d H:i:s',$date_before);

        $data=[$details1,$details2];
        if (isset($tt) && $tt)
        {
            return $data;
        }else{
            return show(config('code.success'),'Success.',$data);
        }
    }

    /**
     *日弧盘数据
     */
    public function solar($tt=[])
    {
        $timeinfo=[];
        $datetime = htmlspecialchars(input('datetime'));
        $timeinfo['timezone'] = (int)(input('timezone'));
        $id = input('id/d', 0);

        if (isset($tt) && $tt)
        {
            $datetime = $tt['datetime'];
            $timeinfo['timezone'] = $tt['timezone'];
            $id = $tt['id'];
            $tid = $tt['tid'];
        }


        $time = strtotime($datetime);
        $timeinfo['year'] = date('Y',$time);
        $timeinfo['month'] = date('m',$time);
        $timeinfo['day'] = date('d',$time);
        $timeinfo['hour'] = date('H',$time);
        $timeinfo['minute'] = date('i',$time);

        $timeinfo['is_summer'] = isSummerTime($timeinfo['hour'],$timeinfo['minute'],0,
            $timeinfo['month'],$timeinfo['day'],$timeinfo['year']) ? 1 : 0;

        $Data = $this->Data;

        $map = ['id' => $id, 'uid' => $this->user['id']];

        $userinfo =$this->recodeModel->getRecode($map);

        $timestamp1 = $Data->deal_time($userinfo);

        $longitude = ($userinfo['long_deg'] + $userinfo['long_min'] / 60 ) * $userinfo['ew'];
        $latitude = ($userinfo['lat_deg'] + $userinfo['lat_min'] / 60 ) * $userinfo['ns'];

        $timestamp2 = $Data->deal_time($timeinfo);

        $birth_JD = gregoriantojd(date('m',$timestamp1), date('d',$timestamp1), date('Y',$timestamp1)) - 0.5 + ((date('H',$timestamp1) + (date('i',$timestamp1) / 60)) / 24);
        $start_JD = gregoriantojd(date('m',$timestamp2), date('d',$timestamp2), date('Y',$timestamp2)) - 0.5 + ((date('H',$timestamp2) + (date('i',$timestamp2) / 60)) / 24);
        $days_alive = $start_JD - $birth_JD; // 总天数
        $prog_time_to_add = $days_alive / 365.2422;// 365.2422  365.2421990  365.25

        $jd_to_use = $birth_JD + $prog_time_to_add;


        $utdatenow1 = strftime("%d.%m.%Y", $timestamp1);
        $utnow1 = strftime("%H:%M:%S", $timestamp1);

        $Set = $this->AstroSet;

        $astro_set = $Set->get(true,'solar',false,$tid);// 内部调用
        $h_sys = $astro_set['value']['h_sys'];

        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

        $options1 = ['utdatenow' => $utdatenow1, 'utnow' => $utnow1, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];

        $out1 = $Data->execData($options1);

        $exec_str2 = config('astrolog.prefix')." -bj{$jd_to_use} -ut -p0 -eswe -fl -g, -head";

        exec ($exec_str2, $out2);
        $original_data1 = $Data->getOriginalData($out1,$h_sys);
        $Data->array_remove($original_data1,$Data->planets_display);

        $p_sun = $out2[0];
        $original_data2 = $Data->getTheLongitudeBySolarArc($p_sun, $original_data1);

        $details1 = $Data->getPlanetHouseDetail($original_data1, $original_data1['hc1']);
        $details2 = $Data->getPlanetHouseDetail($original_data2, $original_data1['hc1']);
        $phase1 = $Data->planetPkPlanet($original_data1, $original_data2, false, 1);
        foreach ($phase1['planets'] as $k1 => $d1)
        {
            $details1['planets'][$k1]['phase'] = $d1['phase'];
            if(empty($d1['phase'])) $details1['planets'][$k1]['phase'] = null;
        }
        $details1['phase'] = $phase1['phase'];
        $phase2 = $Data->planetPkPlanet($original_data2, $original_data1, false, 2);
        foreach ($phase2['planets'] as $k2 => $d2)
        {
            $details2['planets'][$k2]['phase'] = $d2['phase'];
            if(empty($d2['phase'])) $details2['planets'][$k2]['phase'] = null;
        }
        $details2['phase'] = $phase2['phase'];

        $details1['planets'] = (object)$details1['planets'];// 指定输出为object  防止所有行星全开时 类型改变
        $details2['planets'] = (object)$details2['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        $data = [$details1,$details2];

        if (isset($tt) && $tt)
        {
            return $data;

        }else{
            return show(config('code.success'),'Success.',$data);
        }
    }

    /**
     * 日返盘数据
     */
    public function solar_return($tt=[])
    {
        $timeinfo=[];
        $datetime = htmlspecialchars(input('datetime'));
        $timeinfo['timezone'] = (int)(input('timezone'));
        $id = input('id/d', 0);

        if (isset($tt) && $tt)
        {
            $datetime = $tt['datetime'];
            $timeinfo['timezone'] = $tt['timezone'];
            $id = $tt['id'];
            $tid = $tt['tid'];
        }


        $time = strtotime($datetime);
        $timeinfo['year'] = date('Y',$time);
        $timeinfo['month'] = date('m',$time);
        $timeinfo['day'] = date('d',$time);
        $timeinfo['hour'] = date('H',$time);
        $timeinfo['minute'] = date('i',$time);

        $timeinfo['is_summer'] = isSummerTime($timeinfo['hour'],$timeinfo['minute'],0,
            $timeinfo['month'],$timeinfo['day'],$timeinfo['year']) ? 1 : 0;

        $Data = $this->Data;

        $map = ['id' => $id, 'uid' => $this->user['id']];

        $userinfo = $this->recodeModel->getRecode($map);

        $timestamp1 = $Data->deal_time($userinfo);

        $longitude = ($userinfo['long_deg'] + $userinfo['long_min'] / 60 ) * $userinfo['ew'];
        $latitude = ($userinfo['lat_deg'] + $userinfo['lat_min'] / 60 ) * $userinfo['ns'];

        $timestamp2 = $Data->deal_time($timeinfo);

        $birth_JD = gregoriantojd(date('m',$timestamp1), date('d',$timestamp1), date('Y',$timestamp1)) + ((date('H',$timestamp1) + (date('i',$timestamp1) / 60)) / 24);
        $start_JD = gregoriantojd(date('m',$timestamp2), date('d',$timestamp2), date('Y',$timestamp2)) + ((date('H',$timestamp2) + (date('i',$timestamp2) / 60)) / 24);
        $days_alive = $start_JD - $birth_JD; // 总天数

        $year_ago = floor($days_alive / 365.2422);// 365.2422  365.2421990  365.25

        $now_before = strtotime("+$year_ago year",$timestamp1);
        $now_after = strtotime("+1 day",$now_before);

        $utdatenow = strftime("%d.%m.%Y", $timestamp1);
        $utnow = strftime("%H:%M:%S", $timestamp1);

        $utdatenow1 = strftime("%d.%m.%Y", $now_before);
        $utnow1 = strftime("%H:%M:%S", $now_before);

        $utdatenow2 = strftime("%d.%m.%Y", $now_after);
        $utnow2 = strftime("%H:%M:%S", $now_after);

        $Set = $this->AstroSet;

        $astro_set = $Set->get(true,'solar_return',false,$tid);// 内部调用
        $h_sys = $astro_set['value']['h_sys'];

        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

        $options1 = ['utdatenow' => $utdatenow, 'utnow' => $utnow, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];
        $options2 = ['utdatenow' => $utdatenow1, 'utnow' => $utnow1, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];
        $options3 = ['utdatenow' => $utdatenow2, 'utnow' => $utnow2, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];

        $out1 = $Data->execData($options1);
        $out2 = $Data->execData($options2);
        $out3 = $Data->execData($options3);

        // 出生生日那一天太阳位置
        $longtitude1 = number_format(explode(',',$out1[0])[0] * 1,3);
        // 当年生日前一天的太阳位置
        $longtitude2 = number_format(explode(',',$out2[0])[0] * 1,3);
        // 当年生日后一天太阳位置
        $longtitude3 = number_format(explode(',',$out3[0])[0] * 1,3);

        $diff_longtitude = round(abs($longtitude3 - $longtitude2),6);//度数差

        $diff_minutes = 24 * 60 * 60;//精确到秒

        $diff_influence = $diff_longtitude / $diff_minutes;// 每秒钟走的度数

        // 需要多少时间  回到需要的度数
        $second = floor(abs($longtitude1 - $longtitude2) / $diff_influence);// 总秒钟数

        if ($longtitude1 < $longtitude2) $now_before -= $second;

        else $now_before += $second;

        $now_before = $now_before - ($now_before % 60) ;// 只精确到分钟

        $utdatenow_test = strftime("%d.%m.%Y", $now_before);
        $utnow_test  = strftime("%H:%M:%S", $now_before);

        $options = ['utdatenow' => $utdatenow_test, 'utnow' => $utnow_test, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];

        $out = $Data->execData($options);

        $original_data = $Data->getOriginalData($out,$h_sys);
        $Data->array_remove($original_data,$Data->planets_display);

        $details = $Data->getPlanetHouseDetail($original_data, $original_data['hc1']);
        $phase = $Data->planetPkPlanet($original_data, $original_data, true);
        foreach ($phase['planets'] as $k => $d)
        {
            $details['planets'][$k]['phase'] = $d['phase'];
            if(empty($d['phase'])) $details['planets'][$k]['phase'] = null;
        }
        $details['phase'] = $phase['phase'];

        $details['return_time'] = date("Y-m-d H:i",$now_before + $userinfo['timezone'] * 3600);

        $details['planets'] = (object)$details['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        if (isset($tt) && $tt)
        {
            return $details;
        }else{
            return show(config('code.success'),'Success.',$details);
        }
    }

    /**
     * 三限盘数据
     */
    public function thirdprogressed($datetime = null,$in = false,$timezone=0,$id=0,$tid=0,$is_new=false)
    {
        $Set = $this->AstroSet;
        $astro_set = $Set->get(true,'thirdprogressed',$in,$tid);// 内部调用
        $Data = $this->Data;
        $h_sys = $astro_set['value']['h_sys'];
        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

//        if($datetime === null) $datetime = htmlspecialchars(input('datetime'));

        $time = strtotime($datetime);
        $timeinfo = [
            'year'=>date('Y',$time),
            'month'=>date('m',$time),
            'day'=>date('d',$time),
            'hour'=>date('H',$time),
            'minute'=>date('i',$time),
        ];
        $timeinfo['timezone'] =  $timezone == 0 ? (int)(input('timezone')) : $timezone;
        $id =  $id == 0 ? (int)(input('id/d',0)) : $id;
        $timeinfo['is_summer'] = isSummerTime($timeinfo['hour'],$timeinfo['minute'],0,
            $timeinfo['month'],$timeinfo['day'],$timeinfo['year']) ? 1 : 0;

        $map = ['id' => $id, 'uid' => $this->user['id']];

        if(empty($this->recode))
        {
            $RecodeModel = $this->recodeModel;

            $userinfo = $RecodeModel->getRecode($map);
        }else{
            $userinfo = $this->recode;
        }


        $timestamp1 = $Data->deal_time($userinfo);

        $utdatenow = strftime("%d.%m.%Y", $timestamp1);
        $utnow = strftime("%H:%M:%S", $timestamp1);

        $longitude = ($userinfo['long_deg'] + $userinfo['long_min'] / 60 ) * $userinfo['ew'];
        $latitude = ($userinfo['lat_deg'] + $userinfo['lat_min'] / 60 ) * $userinfo['ns'];

        $exec_str  = config('astrolog.prefix')." -b{$utdatenow} -ut{$utnow} -p0 -eswe -house{$longitude},{$latitude},{$h_sys} -fj -g, -head";
        exec ($exec_str, $out);

        $timestamp2 = $Data->deal_time($timeinfo);

        $birth_JD = gregoriantojd(date('m',$timestamp1), date('d',$timestamp1), date('Y',$timestamp1)) + ((date('H',$timestamp1) + (date('i',$timestamp1) / 60)) / 24);
        $start_JD = gregoriantojd(date('m',$timestamp2), date('d',$timestamp2), date('Y',$timestamp2)) + ((date('H',$timestamp2) + (date('i',$timestamp2) / 60)) / 24);
        $days_alive = $start_JD - $birth_JD; // 总天数
        $prog_time_to_add = $days_alive / 27.321661; // 多少月  即本命后第几天27.321661     27.3215865

        // 夜间盘
        if($out[0] > 0 || $out[0] < 7)
        {
            $time_before_JD=$birth_JD+floor($prog_time_to_add);
        }
        else
        {
            $time_before_JD=$birth_JD+floor($prog_time_to_add);
        }

        //变化比率 //就是$prog_time_to_add的去掉整数的小数
        $time_change_pro=$prog_time_to_add-floor($prog_time_to_add);

        $date_before = strtotime(jdtogregorian($time_before_JD));
        $date_after = strtotime('+1 day',$date_before);

        $utdatenow1 = strftime("%d.%m.%Y", $date_before);
        $utnow1 = strftime("%H:%M:%S", $timestamp1);


        $utdatenow2 = strftime("%d.%m.%Y", $date_after);
        $utnow2 = strftime("%H:%M:%S", $timestamp1);

        $options1 = ['utdatenow' => $utdatenow1, 'utnow' => $utnow1, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];
        $options2 = ['utdatenow' => $utdatenow2, 'utnow' => $utnow2, 'longitude' => $longitude, 'latitude' => $latitude, 'h_sys' => $h_sys];

        $out1 = $Data->execData($options1);
        $out2 = $Data->execData($options2);

        $calOut = $Data->getProgressionThirdprogressed($out1,$out2,$time_change_pro);

        $original_data = $Data->getOriginalData($calOut,$h_sys);
        $Data->array_remove($original_data,$Data->planets_display);

        $details = $Data->getPlanetHouseDetail($original_data, $original_data['hc1']);
        $phase = $Data->planetPkPlanet($original_data, $original_data, true);
        foreach ($phase['planets'] as $k => $d)
        {
            $details['planets'][$k]['phase'] = $d['phase'];
            if(empty($d['phase'])) $details['planets'][$k]['phase'] = null;
        }
        $details['phase'] = $phase['phase'];

        $details['time1'] = date('Y-m-d H:i:s',$date_before);

        $details['planets'] = (object)$details['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        if ($is_new === true)
        {
            return $details;
        }else{
            return json_encode(['code'=>200,'data'=>$details,'msg'=>'Success.']);
        }
    }

    /**
     * 行运盘数据
     */
    public function transits($datetime = null,$timezone=0,$id=0,$tid,$is_new=false)
    {
        //        $datetime = htmlspecialchars(input('datetime'));
//        if($datetime === null) $datetime = htmlspecialchars(input('datetime'));
        $time = strtotime($datetime);
        $timeinfo = [
            'year'=>date('Y',$time),
            'month'=>date('m',$time),
            'day'=>date('d',$time),
            'hour'=>date('H',$time),
            'minute'=>date('i',$time),
        ];
        $timeinfo['timezone'] =  $timezone == 0 ? (int)(input('timezone')) : $timezone;

        $timeinfo['is_summer'] = isSummerTime($timeinfo['hour'],$timeinfo['minute'],0,
            $timeinfo['month'],$timeinfo['day'],$timeinfo['year']);

        $id =  $id == 0 ? input('id/d', 0) : $id;
        $map = ['id' => $id, 'uid' => $this->user['id']];

        if(empty($this->recode))
        {
            $RecodeModel = $this->recodeModel;

            $userinfo = $RecodeModel ->getRecode($map);
        }else{
            $userinfo = $this->recode;
        }

        $Data = $this->Data;

        $timestamp1 = $Data->deal_time($userinfo);
        $utdatenow1 = strftime("%d.%m.%Y", $timestamp1);
        $utnow1 = strftime("%H:%M:%S", $timestamp1);
        $longitude1 = ($userinfo['long_deg'] + $userinfo['long_min'] / 60 ) * $userinfo['ew'];
        $latitude1 = ($userinfo['lat_deg'] + $userinfo['lat_min'] / 60 ) * $userinfo['ns'];

        $timestamp2 = $Data->deal_time($timeinfo);
        $utdatenow2 = strftime("%d.%m.%Y", $timestamp2);
        $utnow2 = strftime("%H:%M:%S", $timestamp2);
        $longitude2 = number_format(floatval(input('longitude')),8);
        $latitude2 = number_format(floatval(input('latitude')),8);

        $Set = $this->AstroSet;

        $astro_set = $Set ->get(true,'transits',false,$tid);// 内部调用
        $h_sys = $astro_set['value']['h_sys'];

        $Data->planets_display = $astro_set['value']['planets_display'];
        $Data->asps_display = $astro_set['value']['asps_display'];
        $Data->asp_orb_all = $astro_set['value']['asp_orb_all'];
        $Data->planet_orb_all = $astro_set['value']['planet_orb_all'];

        $options1 = ['utdatenow' => $utdatenow1, 'utnow' => $utnow1, 'longitude' => $longitude1, 'latitude' => $latitude1, 'h_sys' => $h_sys];
        $options2 = ['utdatenow' => $utdatenow2, 'utnow' => $utnow2, 'longitude' => $longitude1, 'latitude' => $latitude1, 'h_sys' => $h_sys];

        $out1 = $Data->execData($options1);
        $out2 = $Data->execData($options2);

        $original_data1 = $Data->getOriginalData($out1,$h_sys);
        $original_data2 = $Data->getOriginalData($out2,$h_sys);
        $Data->array_remove($original_data1,$Data->planets_display);
        $Data->array_remove($original_data2,$Data->planets_display);

        $details1 = $Data->getPlanetHouseDetail($original_data1, $original_data1['hc1']);
        $phase1 = $Data->planetPkPlanet($original_data1, $original_data2, false,1);
        foreach ($phase1['planets'] as $k1 => $d1)
        {
            $details1['planets'][$k1]['phase'] = $d1['phase'];
            if(empty($d1['phase'])) $details1['planets'][$k1]['phase'] = null;
        }
        $details1['phase'] = $phase1['phase'];
        $details2 = $Data->getPlanetHouseDetail($original_data2, $original_data1['hc1']);
        $phase2 = $Data->planetPkPlanet($original_data2, $original_data1, false,2);
        foreach ($phase2['planets'] as $k2 => $d2)
        {
            $details2['planets'][$k2]['phase'] = $d2['phase'];
            if(empty($d2['phase'])) $details2['planets'][$k2]['phase'] = null;
        }
        $details2['phase'] = $phase2['phase'];

        $details1['planets'] = (object)$details1['planets'];// 指定输出为object  防止所有行星全开时 类型改变
        $details2['planets'] = (object)$details2['planets'];// 指定输出为object  防止所有行星全开时 类型改变

        $data= [$details1,$details2];

        if ($is_new === true)
        {
            return $data;

        }else{
            return json_encode(['code'=>200,'data'=>$data,'msg'=>'Success.']);
        }
    }

}
